

package ifips.s7.modele;

import java.util.ArrayList;
import java.util.Iterator;

public class Etat {


	    protected boolean Initial;
	    protected boolean Final;
            protected int id;

	    protected ArrayList<Transition> Transitions;

	    //
	    // Constructors
	    //

	 /*  public Etat (boolean ini, boolean fin) {

		Initial=ini;
		Final=fin;
		ArrayList Transitions =new ArrayList<Transition>();
			
	    };*/

	    public Etat(int id, boolean i, boolean f){
	        this.id = id;
                this.Initial = i;
	        this.Final = f;
                this.Transitions = new ArrayList<Transition>();

	    };

	    boolean isInitial() {
	        return Initial;
	    }

	    boolean isFinal() {
	        return Final;
	    }
	    
	    boolean existe_lien_par(String l){
	    	
	    	if(Transitions == null)return false;
	    	
	    	for (	Iterator it = Transitions.iterator();it.hasNext();){
	    		
	    			Transition T = (Transition) it.next();
	    		
		    		if(T.getLettre()==l)return true;
	    		}	
	    	
	    	return false;
	    }

	    public ArrayList<Transition> getTransitions(){
	        return Transitions;
	    }

	    public void addTransition(Transition t){
	        this.Transitions.add(t);
	        
	    }

            public int getId(){
                return this.id;
            }

	    ArrayList<Etat> lie_par_lettre(String lettre){
	    	
	    	ArrayList Liste_etat_lie_par_lettre = new ArrayList<Etat>();

	    	//rÃ©cupÃ©ration de l'itÃ©rateur

	    	for (Iterator it = Transitions.iterator(); it.hasNext();) {

	    	// itÃ©ration de la liste

	          	Transition T = (Transition) it.next();

		    	if(T.getLettre().equals(lettre) && !Liste_etat_lie_par_lettre.contains(T.getArrivee())){
                            Liste_etat_lie_par_lettre.add(T.getArrivee());
		    	}
	         
	    	}

	    	return Liste_etat_lie_par_lettre;
	    		
	    }
	    
	    
	 
	

}
